﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TicketsPhone.FrontEnd.Models;
using TicketsPhone.Domain.Access;
using TicketsPhone.Negocio;
using TicketsPhone.Domain.Entities;

namespace TicketsPhone.FrontEnd.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Reservar()
        {
            ReservarModel modelo = new ReservarModel();
            modelo.Entidades = new EntidadRepositorio().ObtenerActivos();
            return View(modelo);
        }

        [HttpPost]
        public ActionResult Reservar(ReservarModel modelo)
        {
            if (ModelState.IsValid)
            {
                TurnosNegocio turnosNegocio = new TurnosNegocio();
                Turno turno = new Turno();
                turno.IdSucursal = modelo.IdSucursal;
                turno.HoraInicio = new Domain.Utils.Hora(string.Format("{0}:{1}:00", modelo.Hora, modelo.Minuto));
                
                turnosNegocio.Crear(SesionModel.IdUsuario, modelo.Tramite.Value, turno);
            }

            return View();
        }


        public ActionResult TurnoGenerado(int id)
        {

            return null;
        }
    }
}
